package com.ebt.m.customer.fakeDialog.util;

import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.StateListDrawable;
import android.graphics.drawable.shapes.RoundRectShape;

public class DrawableUtil {

	/**
	 * @return
	 */
	public static Drawable getStateListDrawable(int padding, int radius){

    	StateListDrawable stateListDrawable = new StateListDrawable();

    	int[] stateHighlighted = new int[]{android.R.attr.state_pressed};
    	Drawable highlightedDrawable = getRectLayerDrawable(padding, radius, 0xffeeeeee, 0xffbbbbbb);
    	stateListDrawable.addState(stateHighlighted, highlightedDrawable);

    	int[] stateNormal = new int[]{};
    	Drawable normalDrawable = getRectLayerDrawable(padding, radius, 0xfff4f4f4, 0xffbbbbbb);
    	stateListDrawable.addState(stateNormal, normalDrawable);

    	return stateListDrawable;
    }
    
	/**
	 * @return
	 */
    private static Drawable getRectLayerDrawable(int padding, int radius, int colorFg, int colorBg){
    	
    	float[] outerR = new float[] { radius, radius, radius, radius, radius, radius, radius, radius };
    	RoundRectShape roundRectShapeBg = new RoundRectShape(outerR, null, null);
    	RoundRectShape roundRectShapeFg = new RoundRectShape(outerR, null, null);
    	
    	ShapeDrawable shapeDrawableBg = new ShapeDrawable();
    	shapeDrawableBg.setPadding(0, 0, 0, 0);
    	shapeDrawableBg.setShape(roundRectShapeBg);
    	shapeDrawableBg.getPaint().setStyle(Paint.Style.FILL);
    	shapeDrawableBg.getPaint().setColor(colorBg);

    	ShapeDrawable shapeDrawableFg = new ShapeDrawable();
    	shapeDrawableFg.setPadding(padding, padding, padding, padding);
    	shapeDrawableFg.setShape(roundRectShapeFg);
    	shapeDrawableFg.getPaint().setStyle(Paint.Style.FILL);
    	shapeDrawableFg.getPaint().setColor(colorFg);
    	
    	Drawable[] layers = {shapeDrawableBg, shapeDrawableFg};
    	LayerDrawable layerDrawable = new LayerDrawable(layers);
    	layerDrawable.setLayerInset(1, -1, -1, 1, 1);
    	
    	return layerDrawable;
    }
    
    
    
    
}
